<?php

namespace longhu\services\easywechat\listener\store;

use EasyWeChat\OfficialAccount\Message;
use longhu\library\WechatService;
use think\facade\Log;

/**
 * 事件处理
 */
class EventMessage implements MessageInterface
{
    public function send(Message $message)
    {
        $messageData = $message->toArray();
        $eventName = $messageData['Event']??'';
        //$eventKey = $messageData['EventKey']??'';
        $methonName = $eventName.'Message';
        if(method_exists(self::class,$methonName)){
            return $this->{$methonName}($message);
        }
        return  '';
    }

    //关注消息
    public function subscribeMessage(Message $message)
    {
        $message = $message->toArray();
        $fromUserName = $message['FromUserName']??'';
        //todo 可以更具$fromUserName（既open_id）查询用户名称;

        return '欢迎关注 惠多葆===>';
    }

    //取消关注事件
    public function unsubscribeMessage($message)
    {
        return '';
    }
}